import { getPublicModelList } from "@/api";
import { getSearchFilter } from "@/common/function";
const state = {
  // 订单状态
  roleList: [],
  technicianMenuList: [],
  technicianSettingList: [],
};

const mutations = {
  // 设置角色列表
  SET_ROLE_LIST(state, data) {
    state.roleList = data?.[0]?.tableField110;
  },
  SET_TECHNICIAN_MENU(state, data) {
    state.technicianMenuList = data?.[0]?.tableField113;
  },
  SET_TECHNICIAN_SETTING(state, data) {
    state.technicianSettingList = data?.[0]?.tableField117;
  },
};

const actions = {
  // 获取角色列表
  getRoleList({ commit }) {
    let filterData = {
      currentPage: 1,
      pageSize: -1,
      filter: getSearchFilter({ key: "role_list" }, { method: "like" }),
    };
    return new Promise((resolve, reject) => {
      getPublicModelList("65e032fc5efd5153ff5645fb", filterData)
        .then((res) => {
          commit("SET_ROLE_LIST", res?.data?.list);
          resolve(res);
        })
        .catch((err) => {
          reject(err);
        });
    });
  },
  // 获取技师菜单
  getTechnicianMenu({ commit }) {
    let filterData = {
      currentPage: 1,
      pageSize: -1,
      filter: getSearchFilter({ key: "technician_menu" }, { method: "eq" }),
    };
    return new Promise((resolve, reject) => {
      getPublicModelList("65e032fc5efd5153ff5645fb", filterData)
        .then((res) => {
          resolve(res);
          commit("SET_TECHNICIAN_MENU", res?.data?.list);
        })
        .catch((err) => {
          reject(err);
        });
    });
  },
  // 获取技师设置
  getTechnicianSetting({ commit }) {
    let filterData = {
      currentPage: 1,
      pageSize: -1,
      filter: getSearchFilter({ key: "technician_setting" }, { method: "eq" }),
    };
    return new Promise((resolve, reject) => {
      getPublicModelList("65e032fc5efd5153ff5645fb", filterData)
        .then((res) => {
          resolve(res);
          commit("SET_TECHNICIAN_SETTING", res?.data?.list);
        })
        .catch((err) => {
          reject(err);
        });
    });
  },
};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
};
